﻿using CarEdge.Infrastructure.Dto.Request.Dic;
using CarEdge.Service.Interface;
using CarEdge.Service.Interface.Dic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.Design;

namespace CarEdge.Admin.Controllers.dictionary
{

    /// <summary>
    /// 字典管理
    /// </summary>
    /// 

    [Authorize(Roles = "Admin")]
    public class dictionaryController : BaseController
    {
        private readonly I_Dic_Service _dic_Service;

       /// <summary>
       /// /
       /// </summary>
       /// <param name="dic_Service"></param>
       /// <param name="login_Service"></param>
        public dictionaryController(I_Dic_Service dic_Service, I_Login_Service login_Service) : base(login_Service)
        {
            _dic_Service = dic_Service;
        }

        /// <summary>
        /// 获取字典列表
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
       
        public async Task<IActionResult> Get_AllDic_Type(int? page=1,int? limit=10,string? key="")
        {
            var result = await _dic_Service.Get_AllDic_Type(page ?? 1, limit ?? 10, key ?? "");
            return Ok(result);
        }
        /// <summary>
        /// 删除字典
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public  async Task<IActionResult> Delete_Dictionarys(Dic_Request_Dto dto)
        {
            var result = await _dic_Service.Delete_Dictionarys(dto.ids);
            return Ok(result);

        }
        /// <summary>
        /// 删除字典类别
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]

        public async Task<IActionResult> Delete_Dictionary_Type(Dic_Request_Dto dto)
        {
            var result=await _dic_Service.Delete_Dic_Types(dto.ids);
            return Ok(result);
        }
        /// <summary>
        /// 获取单个字典类别
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Single_Dic(string id)
        {
            var result=await _dic_Service.Get_Single_Dic_Type(id);
            return Ok(result);
        }
        /// <summary>
        /// 新增字典
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Dic(Dic_Request_Dto dto) { 
        
            var user=await this.Get_Curr_User();
            dto.author = user.Uid;
            var result= await _dic_Service.Add_Dictionary(dto);
            return Ok(result);
        }
        /// <summary>
        /// 新增字典类别
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Dic_Type(Dic_Request_Dto dto)
        {
            var user = await this.Get_Curr_User();
            dto.author = user.Uid;
            var result = await _dic_Service.Add_Dictionary_Type(dto);
            return Ok(result);
        }
        /// <summary>
        /// 修改字典类型
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Up_Dic(Dic_Request_Dto dto)
        {
            var user = await this.Get_Curr_User();
            dto.Up_author = user.Uid;
            var result = await  _dic_Service.Up_Dic(dto);
            return Ok(result);
        }
        /// <summary>
        /// 编辑修改字典信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Edit_Dic(Dic_Request_Dto dto)
        {
            var user = await this.Get_Curr_User();
            dto.Up_author=user.Uid;
            var result = await _dic_Service.Edit_Dic(dto);
            return Ok(result);
        }

        /// <summary>
        /// 获取字典，根据类别Key  [keys]
        /// </summary>
        /// <param name="dto">key集合</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Get_Dictionary_ByKey(Dic_Request_Dto dto)
        {
            var result = await _dic_Service.Get_Dictionary_ByKey(dto.keys!);
            return Ok(result);
        }

    }
}
